package com.sec.android.app.myfiles.launch;

import android.app.Activity;
import android.content.Intent;

import com.sec.android.app.myfiles.info.AppConstants;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.util.chain.Chain;

public abstract class AbsHandleLaunchImp implements Chain<AbsHandleLaunchImp> {
    // lower version compatibility
    public static final int IMAGES = 2;
    public static final int VIDEOS = 3;
    public static final int MUSIC = 4;
    public static final int DOCUMENTS = 5;
    public static final int APKS = 6;//add for china feature:category Apk 
    private AbsHandleLaunchImp mNext;

    @Override
    public void setNext(AbsHandleLaunchImp next) {
        mNext = next;
    }

    public boolean handleStart(int processId, Activity activity, Intent intent) {
        boolean ret = false;
        if (isMyJob(intent)) {
            ret = _handleStart(processId, activity, intent);
        } else {
            if (mNext != null) {
                ret = mNext.handleStart(processId, activity, intent);
            }
        }

        return ret;
    }

    protected FileRecord.CategoryType getCategory(Intent intent) {
        FileRecord.CategoryType ret = FileRecord.CategoryType.None;

        int categoryType = intent.getIntExtra(AppConstants.MyFilesExtras.EXTRA_CATEGORY_TYPE, 0);

        switch (categoryType) {
            case IMAGES:
                ret = FileRecord.CategoryType.Image;
                break;
            case VIDEOS:
                ret = FileRecord.CategoryType.Video;
                break;
            case MUSIC:
                ret = FileRecord.CategoryType.Audio;
                break;
            case DOCUMENTS:
                ret = FileRecord.CategoryType.Document;
                break;
            case APKS:
                ret = FileRecord.CategoryType.Apk;
                break;
        }

        return ret;
    }

    public abstract boolean isMyJob(Intent intent);

    public abstract boolean _handleStart(int processId, Activity activity, Intent intent);
}
